// 商品分类的仓库
import { defineStore } from 'pinia'
import {
  reqCategory1,
  reqCategory2,
  reqCategory3,
} from '@/services/product/attr'
import {
  CategoryResponseData,
  CategoryState,
} from '@/services/product/attr/type'
import { reactive } from 'vue'
const useCategoryStore = defineStore('Categort', () => {
  // 一级分类
  const categoryInfo = reactive<CategoryState>({
    Category1Data: [],
    categoryId1: '',
    Category2Data: [],
    categoryId2: '',
    Category3Data: [],
    categoryId3: '',
  })

  // 获取一级分类的数据
  const getReqCategory1 = async () => {
    const res: CategoryResponseData = await reqCategory1()
    if (res.code == 200) {
      categoryInfo.Category1Data = res.data
    }
  }

  // 获取二级分类的数据
  const getReqCategory2 = async () => {
    const res: CategoryResponseDat = await reqCategory2(
      categoryInfo.categoryId1,
    )
    if (res.code == 200) {
      categoryInfo.Category2Data = res.data
    }
  }

  // 获取三级分类的数据
  const getReqCategory3 = async () => {
    const res: CategoryResponseDat = await reqCategory3(
      categoryInfo.categoryId2,
    )
    if (res.code == 200) {
      categoryInfo.Category3Data = res.data
    }
  }
  return {
    getReqCategory1,
    getReqCategory2,
    getReqCategory3,
    categoryInfo,
  }
})
export default useCategoryStore
